package com.fenxiangtech.mall.service.impl;

import com.fenxiangtech.mall.exception.BannerMissException;
import com.fenxiangtech.mall.service.BannerService;
import com.fenxiangtech.mall.dao.BannerDao;
import com.fenxiangtech.mall.entity.Banner;
import com.fenxiangtech.mall.entity.BannerItem;
import com.fenxiangtech.mall.service.BannerItemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhangjiashun
 */
@Service
public class BannerServiceImpl implements BannerService {

    private static Logger logger = LoggerFactory.getLogger(BannerServiceImpl.class);

    @Autowired
    private BannerDao bannerDao;

    @Autowired
    private BannerItemService bannerItemService;

    @Override
    public Banner getBannerById(Long id) throws RuntimeException {
        Banner banner = bannerDao.getBannerById(id);
        if (banner == null) {
            throw new BannerMissException();
        }
        List<BannerItem> items = bannerItemService.listBannerItemByBannerId(banner.getId());
        banner.setItems(items);
        return banner;
    }
}
